package org.lalib.entity.object.variable.value;

import java.util.ArrayList;
import java.util.List;

import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
import com.google.gson.reflect.TypeToken;

public class DropDownVariableBean {

	private Integer removeId = 0;

	private List<DropDownValue> dropDownListVariableBeans = new ArrayList<>();

	public void addValue() {
		dropDownListVariableBeans.add(new DropDownValue());
	}

	public void removeValue() {
		dropDownListVariableBeans.remove(removeId);
	}

	public String getValueAsString() {
		return new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(getDropDownListVariableBeans());
	}

	@SuppressWarnings("unchecked")
	public void getValueFromJson(String value) {
		setDropDownListVariableBeans(((List<DropDownValue>) new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
				.fromJson(value, new TypeToken<List<DropDownValue>>() {
				}.getType())));
	}

	public class DropDownValue {

		public DropDownValue() {
			setValue("");
		}

		@Expose
		private String value;

		public String getValue() {
			return value;
		}

		public void setValue(String value) {
			this.value = value;
		}
	}

	public Integer getRemoveId() {
		return removeId;
	}

	public void setRemoveId(Integer removeId) {
		this.removeId = removeId;
	}

	public List<DropDownValue> getDropDownListVariableBeans() {
		return dropDownListVariableBeans;
	}

	public void setDropDownListVariableBeans(List<DropDownValue> dropDownListVariableBeans) {
		this.dropDownListVariableBeans = dropDownListVariableBeans;
	}
}
